package Week4.J0510;

import java.util.ArrayList;

public class 城市群数量 {
    int n;
    boolean[] isVis = new boolean[222];
    public int citys (ArrayList<ArrayList<Integer>> m) {
        n = m.size();

        int ret = 0;
        for (int i = 0; i < n; i++) {
            if (!isVis[i]) {
                ret++;
                dfs(m, i);
            }
        }
        return ret;
    }

    private void dfs(ArrayList<ArrayList<Integer>> m, int pos) {

        isVis[pos] = true;

        for (int i = 0; i < n; i++) {
            if (m.get(pos).get(i) == 1 && !isVis[i]) {
                dfs(m, i);
            }
        }
    }
}
